// mircoApp/car-manage/components/car-number-keyboard/car-number-keyboard.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false,
    },
    radio: {
      type: null,
    },
    licensePlate: {
      type: null,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    selectProvince: ["", "", "", "", "", "", "", ""],
    selectInd: null,
    provincesShow: false
  },
  observers: {
    "licensePlate": function (rval) {
      console.log(rval);
      if (rval == "0") {
        this.setData({
          selectProvince: ["", "", "", "", "", "", "", ""],
          selectInd:0,
          keyboardType:1
        });
        return;
      } else {
        this.setData({
          selectProvince: ["", "", "", "", "", "", ""],
          selectInd:0,
          keyboardType:1
        });
        return;
      }
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onClickLeft() {
      this.triggerEvent("onClickLeft");
      this.setData({
        selectInd: 0
      })
    },
    onClickRight() {
      this.triggerEvent("onClickRight", {
        selectProvince: this.data.selectProvince,
        license_colour: this.data.licensePlate,
        car_type: this.data.radio
      });
    },
    onChange(e) {
      this.triggerEvent("radioChange", e.detail);
      this.setData({
        selectInd: 0
      })
    },
    onChange_l(e) {
      this.triggerEvent("radioChange_l", e.detail);
      this.setData({
        selectInd: 0
      })
    },
    provincesShowTap(e) {
      let index = e.currentTarget.dataset.index;
      this.setData({
        selectInd: index,
      });
      if (index == 0) {
        this.setData({
          keyboardType: 1,
        });
      } else if (index >= 1) {
        this.setData({
          keyboardType: 2,
        });
      }
      let keyboard = this.selectComponent("#keyboard");
      keyboard.show();
    },
    clickChild(e) {
      let ind = e.detail.ind;
      let key = e.detail.key;
      this.data.selectProvince[ind] = key;
      if (ind < this.data.selectProvince.length - 1) {
        this.data.selectInd = ind + 1;
        if (this.data.selectInd == 0) {
          this.data.keyboardType = 1;
        } else if (this.data.selectInd > 0) {
          this.data.keyboardType = 2;
        }
      }
      this.setData({
        selectProvince: this.data.selectProvince,
        keyboardType: this.data.keyboardType,
        selectInd: this.data.selectInd
      })
    },
    delete(e) {
      let ind = e.detail;
      this.data.selectProvince[ind] = "";
      this.setData({
        selectProvince: this.data.selectProvince
      })
    }
  },
});